[Win32] Look up installation prefix at run-time, replace prefix in
authorTor Lillqvist <tml@iki.fi>
Mon, 15 Mar 2004 14:10:08 +0000 (14:10 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Mon, 15 Mar 2004 14:10:08 +0000 (14:10 +0000)
2004-03-15  Tor Lillqvist  <tml@iki.fi>

* queryloaders.c (main): [Win32] Look up installation prefix at
run-time, replace prefix in PIXBUF_LIBDIR with that. (#106141)

gdk-pixbuf/ChangeLog
gdk-pixbuf/queryloaders.c

index 7d2a06bef85d494b46a48173e0f41a28178eb3be..2a20a446f5639fe80e3bc2f07f77c51e918e64a7 100644 (file)
@@ -1,7 +1,10 @@
 2004-03-15  Tor Lillqvist  <tml@iki.fi>
 
+       * queryloaders.c (main): [Win32] Look up installation prefix at
+       run-time, replace prefix in PIXBUF_LIBDIR with that. (#106141)
+
        Merges from stable branch that had been left out. (#136282, J. Ali
-       Harlow)
+       Harlow):
 
        Changes for run-time lookup of installation location on Win32:
        
index e2f6bfc91035b310372cf4cd9da0a09e02f3aaf5..21aa320eb053fd174b4cf63ea4f46c12023872ed 100644 (file)
 #endif
 #define SOEXT_LEN (strlen (SOEXT))
 
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
 static void
 print_escaped (const char *str)
 {
@@ -203,6 +207,45 @@ int main (int argc, char **argv)
 {
        gint i;
 
+#ifdef G_OS_WIN32
+       gchar libdir[sizeof (PIXBUF_LIBDIR) + 100];
+       gchar runtime_prefix[1000];
+       gchar *slash;
+
+       strcpy (libdir, PIXBUF_LIBDIR);
+
+       if (g_ascii_strncasecmp (PIXBUF_LIBDIR, GTK_PREFIX, strlen (GTK_PREFIX)) == 0 &&
+           (PIXBUF_LIBDIR[strlen (GTK_PREFIX)] == '/' ||
+            PIXBUF_LIBDIR[strlen (GTK_PREFIX)] == '\\')) {
+               /* GTK_PREFIX is a prefix of PIXBUF_LIBDIR, as it
+                * normally is. Replace that prefix in PIXBUF_LIBDIR
+                * with the installation directory on this machine.
+                * We assume this invokation of
+                * gdk-pixbuf-query-loaders is run from either a "bin"
+                * subdirectory of the installation directory, or in
+                * the insallation directory itself.
+                */
+               GetModuleFileName (NULL, runtime_prefix, sizeof (runtime_prefix));
+
+               slash = strrchr (runtime_prefix, '\\');
+               *slash = '\0';
+               slash = strrchr (runtime_prefix, '\\');
+               if (slash != NULL && g_ascii_strcasecmp (slash + 1, "bin") == 0) {
+                       *slash = '\0';
+               }
+               
+               if (strlen (runtime_prefix) + 1 + strlen (PIXBUF_LIBDIR) - strlen (GTK_PREFIX) < sizeof (libdir)) {
+                       strcpy (libdir, runtime_prefix);
+                       strcat (libdir, "/");
+                       strcat (libdir, PIXBUF_LIBDIR + strlen (GTK_PREFIX) + 1);
+               }
+       }
+
+#undef PIXBUF_LIBDIR
+#define PIXBUF_LIBDIR libdir
+
+#endif
+
        g_printf ("# GdkPixbuf Image Loader Modules file\n"
                "# Automatically generated file, do not edit\n"
                "#\n");